﻿using System.Data;

namespace TPXSDK.NET.Log;

/// <summary>
/// 日志解析器基类
/// </summary>
public class LogParserBase
{
    /// <summary>
    /// 解析后数据集合
    /// </summary>
    public DataTable? Data { get; protected set; }

    /// <summary>
    /// 每列数据缩放因子
    /// </summary>
    public double[]? Scale { get; protected set; }

    /// <summary>
    /// 日志单文件路径
    /// </summary>
    public string? FilePath { get; protected set; }

    /// <summary>
    /// 加载文件数据到DataTable
    /// </summary>
    /// <param name="fileName">日志文件</param>
    public virtual void DoLoad(string fileName) { }

    /// <summary>
    /// 汇报解析过程进度
    /// </summary>
    /// <param name="percent">加载进度0~100</param>
    public void Report(int percent)
    {
        if (Percent != percent)
        {
            Percent = percent;
            LoadingEvent?.Invoke(this);
        }
    }

    /// <summary>
    /// 解析完成通知
    /// </summary>
    public void WorkDone()
    {
        Percent = 100;
        LoadedEvent?.Invoke(this);
    }

    /// <summary>
    /// 当前解析日志进度
    /// </summary>
    public int  Percent { get; private set; }

    /// <summary>
    /// 解析结果错误统计
    /// </summary>
    public int ErrorCount { get; protected set; }

    /// <summary>
    /// 进度汇报事件
    /// </summary>
    public delegate void LoadHandler(LogParserBase sender);

    /// <summary>
    /// 进度汇报事件
    /// </summary>
    public event LoadHandler? LoadingEvent;
    public event LoadHandler? LoadedEvent;
}
